package com.net.xpay.common.manager.impl.open;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.xpay.common.manager.open.OpenAlipayAuthTokenManager;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.xpay.common.dao.open.OpenAlipayAuthTokenMapper;
import com.net.xpay.common.domain.open.OpenAlipayAuthToken;
import com.net.common.manager.AbstractManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@ReadTransactional
public class OpenAlipayAuthTokenManagerImpl extends AbstractManager<OpenAlipayAuthToken> implements OpenAlipayAuthTokenManager {

    @Autowired
    private OpenAlipayAuthTokenMapper mapper;


    @Override
    protected BasicMapper<Long, OpenAlipayAuthToken> getMapper() {
        return mapper;
    }

    @Override
    public OpenAlipayAuthToken findByAlipayNickName(String appkey, String alipayNickName) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(appkey) && !Strings.isNullOrEmpty(alipayNickName));
        OpenAlipayAuthToken condition = new OpenAlipayAuthToken();
        condition.setAppkey(appkey);
        condition.setAlipayNickName(alipayNickName);
        return getByCondition(condition);
    }

    @Override
    public OpenAlipayAuthToken findByIsvBizId(String isvBizId) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(isvBizId));
        OpenAlipayAuthToken condition = new OpenAlipayAuthToken();
        condition.setIsvBizId(isvBizId);
        return getByCondition(condition);
    }
}
